#include "Font.h"

bool Font::Initialize(const char* font_name)
{
    if (_instance!=NULL)
        return false;
    
    Font::_instance = new Font(font_name);
    return true;
}

Font::Font(const char* font_name)
{
    if( TTF_Init() == -1 )
        ApplicationLog::Print("Font::Font - Error initializing ttf",ApplicationLog::ERROR);
    
    font = TTF_OpenFont( "X11.ttf", 16 );
    
    if( font == NULL )
        ApplicationLog::Print("Font::Font - Error opening font",ApplicationLog::ERROR);
}

Font::~Font()
{
    //Close the font that was used
    if ( font!=NULL )
        TTF_CloseFont( font );
    
    // Quit SDL_ttf
    TTF_Quit();
}

SDL_Surface* Font::RenderText(const char* text, SDL_Color textColor)
{
    if (_instance==NULL)
        return NULL;
    
    return TTF_RenderText_Solid( _instance->font, text, textColor );
}

Font* Font::_instance = NULL;
